﻿<views:MvxWpfView
    x:Class="Sidvall.WorkItemManager.UI.Wpf.Views.WebContextView"
    xmlns:views="clr-namespace:MvvmCross.Wpf.Views;assembly=MvvmCross.Wpf"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:vms="clr-namespace:Sidvall.WorkItemManager.UI.ViewModels;assembly=Sidvall.WorkItemManager.UI"
    xmlns:Controls="clr-namespace:Sidvall.WorkItemManager.UI.Wpf.Controls" 
    xmlns:Converters="clr-namespace:Sidvall.UI.Wpf.Converters;assembly=Sidvall.UI.Wpf" 
    xmlns:local="clr-namespace:Sidvall.WorkItemManager.UI.Wpf.Views"
    xmlns:Converters1="clr-namespace:Sidvall.WorkItemManager.UI.Wpf.Converters"
    xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
    mc:Ignorable="d" 
    d:DesignHeight="400" d:DesignWidth="600">

    <views:MvxWpfView.Resources>
        <Converters1:StringToTimeSpanConverter x:Key="StringToTimeSpanConverter"/>
        <Converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <Converters:BooleanToVisibilityConverter x:Key="NotBooleanToVisibilityConverter" Not="True"/>
        <CollectionViewSource x:Key="WebTargets" Source="{Binding ActiveEntity.WebTargets}">
            <CollectionViewSource.SortDescriptions>
                <scm:SortDescription PropertyName="WebAddress" />
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>
    </views:MvxWpfView.Resources>

    <Grid d:DataContext="{d:DesignInstance IsDesignTimeCreatable=True, Type={x:Type vms:WebContextViewModel}}">
        <TabControl>
            <TabItem Header="Targets">
                <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
                    <Grid>
                        <Grid Visibility="{Binding WebTargetListIsVisible, Converter={StaticResource BooleanToVisibilityConverter}}">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>

                            <Grid Grid.ColumnSpan="3" IsEnabled="{Binding CanEdit}">
                                <Grid.Background>
                                    <SolidColorBrush Color="#FFD1E0F1" Opacity="0.6"/>
                                </Grid.Background>
                                <StackPanel Orientation="Horizontal">
                                    <Controls:ButtonControl ImageHeight="36" ImageWidth="36" ImageSource="/Sidvall.WorkItemManager.UI.Wpf;component/Images/Add.png" 
                                        ToolTip="Add web target" ButtonCommand="{Binding AddWebTargetCommand}" />
                                </StackPanel>
                            </Grid>

                            <DataGrid Grid.Row="1" RowHeaderWidth="0" ItemsSource="{Binding  Source={StaticResource WebTargets}}" AutoGenerateColumns="False" CanUserAddRows="False" RowHeight="55" CanUserResizeColumns="False" CanUserReorderColumns="False" CanUserResizeRows="False" SelectedItem="{Binding ActiveWebTarget}">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="MouseDoubleClick">
                                        <i:InvokeCommandAction Command="{Binding EditWebTargetCommand}" CommandParameter="{Binding ActiveWebTarget}" />
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                                <DataGrid.Columns>
                                    <DataGridTemplateColumn Width="60" Header="Enabled" SortMemberPath="IsEnabled">
                                        <DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <CheckBox IsChecked="{Binding IsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalContentAlignment="Center" 
                                                          HorizontalContentAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" 
                                                          IsEnabled="{Binding DataContext.CanEdit, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:WebContextView}}}" />
                                            </DataTemplate>
                                        </DataGridTemplateColumn.CellTemplate>
                                    </DataGridTemplateColumn>
                                    <DataGridTemplateColumn Width="40" Header="Verb" SortMemberPath="HttpVerb">
                                        <DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <TextBlock Text="{Binding HttpVerb}" VerticalAlignment="Center" />
                                            </DataTemplate>
                                        </DataGridTemplateColumn.CellTemplate>
                                    </DataGridTemplateColumn>
                                    <DataGridTemplateColumn Width="*" Header="Web Address" SortMemberPath="WebAddress">
                                        <DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <TextBlock Text="{Binding WebAddress}" TextWrapping="Wrap" VerticalAlignment="Center" />
                                            </DataTemplate>
                                        </DataGridTemplateColumn.CellTemplate>
                                    </DataGridTemplateColumn>
                                    <DataGridTemplateColumn Width="50" Header="Result">
                                        <DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <TextBlock Text="{Binding WebResult.StatusCode}" TextWrapping="Wrap" VerticalAlignment="Center" />
                                            </DataTemplate>
                                        </DataGridTemplateColumn.CellTemplate>
                                    </DataGridTemplateColumn>
                                    <DataGridTemplateColumn Width="35" IsReadOnly="True">
                                        <DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <Button Width="32" Height="32" Background="{x:Null}" BorderBrush="{x:Null}" 
                                                    Command="{Binding DataContext.EditWebTargetCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:WebContextView}}}"
                                                    CommandParameter="{Binding}">
                                                    <Image Source="/Sidvall.WorkItemManager.UI.Wpf;component/Images/Edit.png" ToolTip="Edit web target" />
                                                </Button>
                                            </DataTemplate>
                                        </DataGridTemplateColumn.CellTemplate>
                                    </DataGridTemplateColumn>
                                    <DataGridTemplateColumn Width="35" IsReadOnly="True">
                                        <DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <Button Width="32" Height="32" Background="{x:Null}" BorderBrush="{x:Null}" 
                                                    Command="{Binding DataContext.OpenWebTargetCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:WebContextView}}}"
                                                    CommandParameter="{Binding}">
                                                    <Image Source="/Sidvall.WorkItemManager.UI.Wpf;component/Images/Open.png" ToolTip="Open web target" />
                                                </Button>
                                            </DataTemplate>
                                        </DataGridTemplateColumn.CellTemplate>
                                    </DataGridTemplateColumn>
                                    <DataGridTemplateColumn Width="35" IsReadOnly="True">
                                        <DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <Button Width="32" Height="32" Background="{x:Null}" BorderBrush="{x:Null}" 
                                                    Command="{Binding DataContext.DeleteWebTargetCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:WebContextView}}}"
                                                    CommandParameter="{Binding}"
                                                    Visibility="{Binding DataContext.CanEdit, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:WebContextView}}}">
                                                    <Image Source="/Sidvall.WorkItemManager.UI.Wpf;component/Images/Delete.png" ToolTip="Delete web target" />
                                                </Button>
                                            </DataTemplate>
                                        </DataGridTemplateColumn.CellTemplate>
                                    </DataGridTemplateColumn>
                                </DataGrid.Columns>
                            </DataGrid>
                        </Grid>
                        <Grid Visibility="{Binding WebTargetListIsVisible, Converter={StaticResource NotBooleanToVisibilityConverter}}">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition />
                            </Grid.RowDefinitions>

                            <Grid Grid.ColumnSpan="3">
                                <Grid.Background>
                                    <SolidColorBrush Color="#FFD1E0F1" Opacity="0.6"/>
                                </Grid.Background>
                                <StackPanel Orientation="Horizontal">
                                    <Controls:ButtonControl ImageHeight="36" ImageWidth="36" ImageSource="/Sidvall.WorkItemManager.UI.Wpf;component/Images/Back.png" 
                                        ToolTip="Back to list" ButtonCommand="{Binding ShowWebTargetListCommand}" />
                                </StackPanel>
                            </Grid>
                            <StackPanel Grid.Row="1" IsEnabled="{Binding CanEdit}">
                                <Grid Margin="0,5,5,0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="100" />
                                        <ColumnDefinition />
                                    </Grid.ColumnDefinitions>

                                    <Label Content="Web Address:"/>
                                    <TextBox Grid.Column="1" Text="{Binding ActiveWebTarget.WebAddress}" />
                                </Grid>
                                <Grid Margin="0,5,5,0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="100" />
                                        <ColumnDefinition Width="100" />
                                        <ColumnDefinition />
                                    </Grid.ColumnDefinitions>

                                    <Label Content="Http Verb:"/>
                                    <ComboBox Grid.Column="1" ItemsSource="{Binding HttpVerbs}" SelectedValuePath="Name" DisplayMemberPath="Name" SelectedValue="{Binding ActiveWebTarget.HttpVerb}" />
                                </Grid>
                                <Grid Margin="0,5,5,0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="100" />
                                        <ColumnDefinition />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>

                                    <Label Content="Content:"/>
                                    <TextBox Grid.Column="1" Text="{Binding ActiveWebTarget.Content}" AcceptsReturn="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible" Height="60" />
                                </Grid>
                                <Grid Margin="0,5,5,0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="100" />
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition />
                                    </Grid.ColumnDefinitions>

                                    <Label Content="Enabled:"/>
                                    <CheckBox Grid.Column="1" IsChecked="{Binding ActiveWebTarget.IsEnabled}" VerticalAlignment="Center" />
                                </Grid>
                            </StackPanel>
                        </Grid>
                    </Grid>
                </ScrollViewer>
            </TabItem>
        </TabControl>
    </Grid>
</views:MvxWpfView>
